package com.leospa.main;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Hashtable;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

import com.leospa.bean.Command_0;
import com.leospa.bean.TimerCounter;

public class OptionMassageGuiHandler {
	
	JPanel jPanel1;
	JButton jButton1;
	JLabel jLabel1;
//	Timer timer ;
	Command_0 command_0 ;
	JButton jbButton1;
	public OptionMassageGuiHandler(JPanel jPanel, JButton jButton,JLabel jLabel, final Command_0 command_0,JButton jbButton) {
		jPanel1 = jPanel;
		jButton1 = jButton;
		jLabel1 = jLabel;
		jbButton1 = jbButton;
//		Hashtable massHash = Util.getUtilInstance().getMassageTimerHash();
//		final MassageTimer mas = (MassageTimer)massHash.get(command_0.getSOLARIUMID());
		Hashtable startTimerHash = Util.getUtilInstance().getStartTimeHash();
		TimerCounter timerCounter = (TimerCounter)startTimerHash.get(command_0.getSOLARIUMID());
		if(timerCounter == null) {
			return;
		}
		long startTime = timerCounter.getStartTime();
		long milliseconds = System.currentTimeMillis() - startTime;
		int seconds = (int) milliseconds / 1000;
		int totalTime = timerCounter.getTotalTime();
		int count = totalTime -seconds;
		if(count <= 0){
			jPanel1.setVisible(false);
			jbButton1.setVisible(true);
//			timer.stop();
		} else {
			int sec = count%60;
			String secSt = ""+sec;
			if(sec <10){
				secSt = "0"+sec;
			}
			String minSt = ""+(count/60);
			if((count/60) <10){
				minSt="0"+(count/60);
			}
			jLabel1.setText(""+minSt+":"+secSt+" Min");
		}
//		timer = new Timer(1, new ActionListener() {
//				@Override
//				public void actionPerformed(ActionEvent arg0) {    	    					
//					int count = mas.getTime();
////					if(ConfigPropertiesFile.DEBUG_MODE_ON == true){ System.out.println(command_0.getSOLARIUMID()+"=========="+count);
//					if(count == 0){
//						jPanel1.setVisible(false);
//						jbButton1.setVisible(true);
//						timer.stop();
//					} else {
//						int sec = count%60;
//						String secSt = ""+sec;
//						if(sec <10){
//							secSt = "0"+sec;
//						}
//						String minSt = ""+(count/60);
//						if((count/60) <10){
//							minSt="0"+(count/60);
//						}
//						jLabel1.setText(""+minSt+":"+secSt+" Min");
//					}
//				}
//		});
//		timer.start();
	}

}
